//package com.zyc.service;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.zyc.mapper.RoleMapper;
//import com.zyc.mapper.UserMapper;
//import com.zyc.pojo.RolePojo;
//import com.zyc.pojo.UserPojo;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@Service("userDetailsService")
//@MapperScan("com.zyc.mapper")
//public class userServiceImpl implements UserDetailsService {
//    @Autowired
//    private UserMapper userMapper;
//
//    @Autowired
//    RoleMapper roleMapper;
//
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        QueryWrapper<UserPojo> wrapper =new QueryWrapper<>();
//        wrapper.eq("username",username);
//        UserPojo user =userMapper.selectOne(wrapper);
//        if(user==null) throw new UsernameNotFoundException("用户不存在");
//        else
//        {
//            List<SimpleGrantedAuthority> authorities=new ArrayList<>();
//            QueryWrapper<RolePojo> wrapper1 =new QueryWrapper<>();
//            wrapper1.eq("role",user.getRole());
//            List<RolePojo> rolepojos=roleMapper.selectList(wrapper1);
//            rolepojos.forEach(role->{
//                authorities.add(new SimpleGrantedAuthority(role.getPermission()));
//            });
//            return new User(user.getUsername(),user.getPassword(),authorities);
//        }
//
//
//
//    }
//}
